package com.atguigu.order.service.impl;

import com.atguigu.commonutils.ordervo.CourseWebVoOrder;
import com.atguigu.commonutils.ordervo.UcenterMemberOrder;
import com.atguigu.order.client.EduClient;
import com.atguigu.order.client.UcenterClient;
import com.atguigu.order.entity.TOrder;
import com.atguigu.order.mapper.TOrderMapper;
import com.atguigu.order.service.TOrderService;
import com.atguigu.order.util.OrderNoUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-08-18
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {

    @Autowired
    EduClient eduClient;

    @Autowired
    UcenterClient ucenterClient;

    @Override
    public String createOrder(String courseId, String memberIdByJwtToken) {
        //远程调用，获取对应的课程信息
        CourseWebVoOrder courseOrder = eduClient.getCourseOrder(courseId);
        //远程调用，获取对应的讲师信息
        System.out.println("讲师id"+memberIdByJwtToken);
                                                UcenterMemberOrder userInfoOrder = ucenterClient.getUserInfoOrder(memberIdByJwtToken);
        TOrder tOrder = new TOrder();
        tOrder.setOrderNo(OrderNoUtil.getOrderNo());
        tOrder.setCourseTitle(courseOrder.getTitle());
        tOrder.setCourseCover(courseOrder.getCover());
        tOrder.setCourseId(courseId);
        tOrder.setTeacherName(courseOrder.getTeacherName());
        tOrder.setMemberId(userInfoOrder.getId());
        tOrder.setNickname(userInfoOrder.getNickname());
        tOrder.setMobile(userInfoOrder.getMobile());
        tOrder.setTotalFee(courseOrder.getPrice());
        //支付类型
        tOrder.setPayType(1);
        //支付状态，是否支付
        tOrder.setStatus(0);
        baseMapper.insert(tOrder);
        //返回的是订单号
        return tOrder.getOrderNo();
    }
}
